<template>
  <!--新增员工信息-->
  <div>
    <el-row>
      <el-col :span="22" :offset="1" >

        <el-card class="box-card" shadow="always" style="padding: 0 15px;">

          <el-row>
            <el-col :span="24" :offset="0" style="margin-top:10px;border: 1px solid white">

              <el-form :label-position="labelPosition" :inline="true" :model="form">
                <div style="margin-bottom:-80px;border: 1px solid white">
                  <el-form-item style="width: 100%; line-height:40px;border: 1px solid white">
                    <el-divider direction="vertical" style="size:20px"></el-divider>
                    <span style="color:blue;font-size: 25px;float: left">新增员工信息</span>
                    <el-button type="primary" style="float: right;" @click="back">返回
                    </el-button>
                    <el-button type="primary" @click="onSubmit" style="float: right;margin-right: 10px">修改</el-button>
                    <el-button type="primary" @click="onSubmits" style="float: right;margin-right: 10px">新增</el-button>
                  </el-form-item>
                </div>

                <el-form-item align="left" label="员工编号" class="width270Height40">
                  <el-input v-model="form.empId" placeholder="员工编号"></el-input>
                </el-form-item>
                <el-form-item align="left" label="员工姓名" class="width270Height40">
                  <el-input v-model="form.name" placeholder="员工姓名"></el-input>
                </el-form-item>
                <el-form-item align="left" label="患者年龄" class="width270Height40">
                  <el-input v-model="form.age" placeholder="患者年龄"></el-input>
                </el-form-item>
                <el-form-item align="left" label="性别" class="width270Height40">
                  <el-input v-model="form.sex" placeholder="性别"></el-input>
                </el-form-item>
                <el-form-item align="left" label="手机号码" class="width270Height40">
                  <el-input v-model="form.phone" placeholder="手机号码"></el-input>
                </el-form-item>
                <el-form-item align="left" label="电子邮箱" class="width270Height40">
                  <el-input v-model="form.email" placeholder="电子邮箱"></el-input>
                </el-form-item>
                <el-form-item align="left" label="证件号码" class="width270Height40">
                  <el-input v-model="form.identity" placeholder="证件号码"></el-input>
                </el-form-item>
                <el-form-item align="left" label="职位" class="width270Height40">
                  <el-input v-model="form.position" placeholder="职位"></el-input>
                </el-form-item>
                <el-form-item align="left" label="地址" class="width270Height40" style="width: 100%;">
                  <el-input v-model="form.address" placeholder="地址" style="width: 900px;"></el-input>
                </el-form-item>
                <el-form-item align="left" label="所属科室" class="width270Height40">
                  <el-input v-model="form.department" placeholder="所属科室"></el-input>
                </el-form-item>
                <el-form-item align="left" label="角色" class="width270Height40">
                  <el-input v-model="form.role" placeholder="角色"></el-input>
                </el-form-item><br/>
                <el-form-item align="left" label="密码" class="width270Height40">
                  <el-input v-model="form.password" placeholder="密码"></el-input>
                </el-form-item>

              </el-form>

            </el-col>
          </el-row>

        </el-card>

      </el-col>
    </el-row>
  </div>
</template>

<script>
  import axios from 'axios';
  export default {
    data() {
      return {
        labelPosition: 'top',
        form: {}
      };
    },
    methods: {
      findById(id){
        axios.post("/api/employee/findById",{id:id}).then(res=>{
          this.form=res.data;
        })
      },
      onSubmit() {
        alert("保存成功")
        console.log('submit!');

        axios.post("/api/employee/update",this.form).then(res=>{
          alert(res.data);
          if(res.data=="success"){
            this.$router.push("/employee1")
          }
        })
      }
      ,
      onSubmits() {
        alert("保存成功")
        console.log('submit!');

        axios.post("/api/employee/insert",this.form).then(res=>{
          alert(res.data);
          if(res.data=="success"){
            this.$router.push("/employee1")
          }
        })
      },
      back:function () {
        this.$router.push("/employee")
      }
    },mounted(){

      var id=this.$route.params.id;
      alert(id);
      if(id!=undefined){

        this.findById(id)
      }
    }
  }
</script>

<style scoped>
  .width270Height40{
    width: 270px;line-height:40px;float:left;margin-right:40px;
  }
</style>
